use feature 'state';

sub PrintCount{
	state $count = 0;
	print "value of counter is $count\n";
	$count++;
}

for(1..5){
	PrintCount();
}

#在perl 5.10之前写法要发生改变，因为她没有状态变量。
{
   my $count = 0; # initial value	放在一个块内，防止她污染全局变量名空间

   sub PrintCount {
      print "Value of counter is $count\n";
      $count++;
   }
}

for (1..5){
   PrintCount();
}